<?php
namespace app\index\controller;

use app\index\model\Blog;
use app\index\model\Cate;
use think\Request;

class Index
{
    /*
     * index 显示主页面
     * search实现搜索功能
     */
    public function index()
    {
        /*
         * $data 轮播图
         * $blog 轮播图右侧
         * $four 轮播图左下
         * $seven 特别推荐
         * $eight 推荐文章
         * $nine 点击排行
         */
        $data =(new Cate())->cateselect();
        $blog =(new Blog())->allselect();
        $four =(new Blog())->fourselect();
        $seven =(new Blog())->sevenselect();
        $eight =(new Blog())->eightselect();
        $nine =(new Blog())->nineselect();
        return view('index@index/index',compact('data','blog','four','seven','eight','nine'));
    }
    public function search(Request $request){
        $data =$request->post();
        $shuju =(new Blog())->search($data);
        if($shuju){
            foreach ($shuju as $v) {
                if ($v['cid'] == 1) {
                    return view("index@about/index");
                } else if ($v['cid'] == 35) {
                    return view("index@life/index");
                } else if ($v['cid'] == 36) {
                    return view("index@game/index");
                } else if ($v['cid'] == 37) {
                    return view("index@tour/index");
                }
            }
        }
    }

}
